/*--------------------------------------------------------------------------------
	This Source Code Form is subject to the terms of the Mozilla Public License,
	v. 2.0. If a copy of the MPL was not distributed with this file, You can
	obtain one at https://mozilla.org/MPL/2.0/.
--------------------------------------------------------------------------------*/

    .section	".crt0","ax"
	.code 32
	.align
	.global _start
@---------------------------------------------------------------------------------
_start:
@---------------------------------------------------------------------------------
	b		_start2

@---------------------------------------------------------------------------------
@ AXF addresses
@---------------------------------------------------------------------------------
_text_start:
	.word   __text_start
_ro_end:
	.word   __ro_end
_data_start:
	.word   __data_start
	.word   __bss_end
_bss_start:
	.word   __bss_start
_bss_end:
	.word   __bss_end

@---------------------------------------------------------------------------------
@ GamePark magic sequence
@---------------------------------------------------------------------------------
	.word   0x44450011
	.word   0x44450011
	.word   0x01234567
	.word   0x12345678
	.word   0x23456789
	.word   0x34567890
	.word   0x45678901
	.word   0x56789012
	.word   0x23456789
	.word   0x34567890
	.word   0x45678901
	.word   0x56789012
	.word   0x23456789
	.word   0x34567890
	.word   0x45678901
	.word   0x56789012

@---------------------------------------------------------------------------------
_start2:
@---------------------------------------------------------------------------------
	mrs		r0, CPSR
	orr		r0, r0, #0xC0
	msr		CPSR_ctl, r0

	mrs		r0, CPSR
	bic		r0, r0, #0xC0
	orr		r0, r0, #0x40
	msr		CPSR_ctl,r0

@---------------------------------------------------------------------------------
@ global constructors
@---------------------------------------------------------------------------------
	ldr		r3,=_call_main
	mov		lr,r3
	ldr		r3,=__libc_init_array
	bx		r3
@---------------------------------------------------------------------------------
@ Jump to user code
@---------------------------------------------------------------------------------
_call_main:
@---------------------------------------------------------------------------------
	mov		lr, #0
	ldr		r3, =main
	bx		r3

	.pool
	.end
